﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using LY.Business.ServiceImpl;
using LY.Common;
using LY.Entity;
using LY.Interface;

namespace QJ.CMS.tools
{
    /// <summary>
    /// WebAjax 的摘要说明
    /// </summary>
    public class WebAjax : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            string action = RBSRequest.GetQueryString("action");
            switch (action)
            {

                case "zanclick":  
                    zanclick(context);
                    break;
                case "guanzhuclick":
                    guanzhuclick(context);
                    break;
            }
        }

        private void zanclick(HttpContext context)
        {
            var systemId = RBSRequest.GetQueryString("systemId");

            var msg = string.Empty;
            IProjectService projectService = new ProjectService(); 
           
            var flag = projectService.SaveProjectExpand(Convert.ToInt32(systemId), 1);
            if (flag != null)
            {
                context.Response.Write("{ \"info\":\"赞了一下!\", \"status\":\"y\", \"praise\":\"" + flag.zan + "\" }");
            }
            else
                context.Response.Write("{ \"info\":\"没赞成功!," + msg + "!\", \"status\":\"n\" , \"praise\":\"0\"}");
        }

        private void guanzhuclick(HttpContext context)
        {
            var systemId = RBSRequest.GetQueryString("systemId");
            var member = RBSRequest.GetQueryString("member");
            var msg = string.Empty;
            IProjectService projectService = new ProjectService();

            //发送验证码   
            var flag = projectService.SaveProjectExpand(Convert.ToInt32(systemId), 2);
            if (flag != null)
            {
                //关注成功 关注列表添加记录
                R_ProjectAttention attention = new R_ProjectAttention();
                attention.Addtime = DateTime.Now;
                attention.Projectid = Convert.ToInt32(systemId);
                attention.Member = Convert.ToInt32(member);
                attention.Type = 0;
                IProjectAttentionService projectAttention = new ProjectAttentionService();
                var MSG = projectAttention.AddProjectAttention(attention);
                context.Response.Write("{ \"info\":\"已关注!\", \"status\":\"y\", \"praise\":\"" + flag.guanzhu + "\" }");
            }
            else
                context.Response.Write("{ \"info\":\"关注不成功!," + msg + "!\", \"status\":\"n\" , \"praise\":\"0\"}");
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}